import { loginAPI, LoginFormDataType, sendCodeAPI } from '@/api/login';
import { setToken } from '@/utils/storage';
import { AppDispatch } from '..';

/** 发送验证码Action */
export const sendCodeAction = (mobile: string) => {
  return async () => {
    const res = await sendCodeAPI(mobile);
    console.log('res  ----->  ', res);
  };
};

/** 登录的Action */
export const loginAction = (data: LoginFormDataType) => {
  return async (dispatch: AppDispatch) => {
    const res = await loginAPI(data);
    // 1. 登录成功后，存token到缓存中
    setToken(res.data);
    dispatch({ type: 'user/saveAuth', payload: res.data });
  };
};
